{
  LX RndJob module

  Based on modo's SDK lxrndjob.h which is:

  Copyright (c) 2008-2012 Luxology LLC

  Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the "Software"),
  to deal in the Software without restriction, including without limitation
  the rights to use, copy, modify, merge, publish, distribute, sublicense,
  and/or sell copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.   Except as contained
  in this notice, the name(s) of the above copyright holders shall not be
  used in advertising or otherwise to promote the sale, use or other dealings
  in this Software without prior written authorization.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  DEALINGS IN THE SOFTWARE.
}

{
  Copyright (c) 2012 David Ballesteros and Jameel Halabi

  This unit is part of the BLAISEmodo wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}


unit Lx_RndJob;

{$mode objfpc}{$H+}

interface

uses
  Lx_Result, Lx_Render, Lx_Vector, Lx_Image;

const
  LXa_RENDERSERVICE                = 'renderservice'          ;
  LXa_RENDERJOB                    = 'renderjob'              ;
  LXa_RENDERSTATS                  = 'renderstats'            ;
  LXa_BUFFER                       = 'renderBuffer'           ;
  LXa_FRAMEBUFFER                  = 'frameBuffer'            ;
  LXa_IMAGEPROCESSING              = 'imageprocessing'        ;
  LXa_IMAGEPROCESSINGLISTENER      = 'imageprocessinglistener';
  LXa_IMAGEPROCESSINGREAD          = 'imageprocessingread'    ;
  LXa_IMAGEPROCESSINGSERVICE       = 'imageprocessingservice' ;

  LXfRENDEROPT_NO_WAITING          = $0001;
  LXfRENDEROPT_NO_IMAGE            = $0002;
  LXfRENDEROPT_NO_CLEANUP          = $0004;
  LXfRENDEROPT_IC_ONLY             = $0008;

  // render buffer is not anti-aliased
  LXf_RBF_NO_AA                    = $01;
  // render buffer can be dithered
  LXf_RBF_DITHER                   = $02;
  // render buffer is factory named
  LXf_RBF_IS_FACTORY_NAME          = $08;

  // One of the image processing Set...() methods was called
  LXfIMAGEPROC_EVENT_CHANGED       = $10000000;
  // A mantenance method like Reset() was called
  LXfIMAGEPROC_EVENT_MAINTENANCE   = $20000000;

  LXiRENDERTYPE_FRAME              = 0;
  LXiRENDERTYPE_ANIM               = 1;
  LXiRENDERTYPE_TURNTABLE_CAMERA   = 2;
  LXiRENDERTYPE_TURNTABLE_GEOMETRY = 3;
  LXiRENDERTYPE_BAKE_SCENE         = 4;
  LXiRENDERTYPE_BAKE_TEXTURE       = 5;

  LXiRBD_FLOAT                     = 0;
  LXiRBD_FLOAT3                    = 1;
  LXiRBD_OTHER                     = 2;

  LXiIMAGEPROC_EVENT_CHANGED_OPERATORS                      =
    $00000010 or LXfIMAGEPROC_EVENT_CHANGED    ;
  LXiIMAGEPROC_EVENT_CHANGED_SOURCE_IMAGE_GAMMA             =
    $00000020 or LXfIMAGEPROC_EVENT_CHANGED    ;
  LXiIMAGEPROC_EVENT_CHANGED_SAVE_PROCESSED                 =
    $00000040 or LXfIMAGEPROC_EVENT_CHANGED    ;

  LXiIMAGEPROC_EVENT_CHANGED_BLOOM_ENABLED                  =
    $00000080 or LXfIMAGEPROC_EVENT_CHANGED    ;
  LXiIMAGEPROC_EVENT_CHANGED_BLOOM_THRESHOLD                =
    $00000100 or LXfIMAGEPROC_EVENT_CHANGED    ;
  LXiIMAGEPROC_EVENT_CHANGED_BLOOM_RADIUS                   =
    $00000200 or LXfIMAGEPROC_EVENT_CHANGED    ;

  LXiIMAGEPROC_EVENT_CHANGED_LEVEL_OFFSET                   =
    $00000400 or LXfIMAGEPROC_EVENT_CHANGED    ;

  LXiIMAGEPROC_EVENT_CHANGED_INPUT_BLACK_LEVEL              =
    $00000800 or LXfIMAGEPROC_EVENT_CHANGED    ;
  LXiIMAGEPROC_EVENT_CHANGED_INPUT_GRAY_LEVEL               =
    $00001000 or LXfIMAGEPROC_EVENT_CHANGED    ;
  LXiIMAGEPROC_EVENT_CHANGED_INPUT_WHITE_LEVEL              =
    $00002000 or LXfIMAGEPROC_EVENT_CHANGED    ;

  LXiIMAGEPROC_EVENT_CHANGED_INPUT_MIN_RGB_LEVEL            =
    $00004000 or LXfIMAGEPROC_EVENT_CHANGED    ;
  LXiIMAGEPROC_EVENT_CHANGED_INPUT_GRAY_RGB_LEVEL           =
    $00008000 or LXfIMAGEPROC_EVENT_CHANGED    ;
  LXiIMAGEPROC_EVENT_CHANGED_INPUT_MAX_RGB_LEVEL            =
    $00010000 or LXfIMAGEPROC_EVENT_CHANGED    ;

  LXiIMAGEPROC_EVENT_CHANGED_TONE_MAPPING                   =
    $00020000 or LXfIMAGEPROC_EVENT_CHANGED    ;

  LXiIMAGEPROC_EVENT_CHANGED_HUE_OFFSET                     =
    $00040000 or LXfIMAGEPROC_EVENT_CHANGED    ;
  LXiIMAGEPROC_EVENT_CHANGED_SATURATION                     =
    $00080000 or LXfIMAGEPROC_EVENT_CHANGED    ;
  LXiIMAGEPROC_EVENT_CHANGED_COLORIZATION                   =
    $00100000 or LXfIMAGEPROC_EVENT_CHANGED    ;
  LXiIMAGEPROC_EVENT_CHANGED_TARGET_COLOR                   =
    $00200000 or LXfIMAGEPROC_EVENT_CHANGED    ;

  LXiIMAGEPROC_EVENT_CHANGED_OUTPUT_BLACK_LEVEL             =
    $00400000 or LXfIMAGEPROC_EVENT_CHANGED    ;
  LXiIMAGEPROC_EVENT_CHANGED_OUTPUT_WHITE_LEVEL             =
    $00800000 or LXfIMAGEPROC_EVENT_CHANGED    ;

  LXiIMAGEPROC_EVENT_CHANGED_OUTPUT_MIN_RGB_LEVEL           =
    $01000000 or LXfIMAGEPROC_EVENT_CHANGED    ;
  LXiIMAGEPROC_EVENT_CHANGED_OUTPUT_MAX_RGB_LEVEL           =
    $02000000 or LXfIMAGEPROC_EVENT_CHANGED    ;

  LXiIMAGEPROC_EVENT_CHANGED_OUTPUT_GAMMA                   =
    $04000000 or LXfIMAGEPROC_EVENT_CHANGED    ;
  LXiIMAGEPROC_EVENT_CHANGED_RESPECT_RENDER_VIEW_GAMMA_PREF =
    $08000000 or LXfIMAGEPROC_EVENT_CHANGED    ;

  LXiIMAGEPROC_EVENT_RESET                                  =
    $00000001 or LXfIMAGEPROC_EVENT_MAINTENANCE;

  LXiRENDEREYE_MONO                = 0;
  LXiRENDEREYE_LEFT                = 1;
  LXiRENDEREYE_RIGHT               = 2;

  // Reserved for internal use (see above)
  LXmIMAGEPROC_EVENT_RESERVED      = $0000000F;

  LXu_RENDERSERVICE                = '{8D1710CE-7AF4-46cd-B6B1-222A7DC4C53F}';
  LXu_RENDERJOB                    = '{091C8EB2-5DC1-4d01-AF9B-3C735F2FFB1D}';
  LXu_RENDERSTATS                  = '{091C8EB2-5DC1-4d01-AF9B-3C735F2FFB1D}';
  LXu_BUFFER                       = '{088D0A6B-7A83-4774-AA56-473F6C241F40}';
  LXu_FRAMEBUFFER                  = '{90B060B4-1EC2-45F4-A6A8-9A3822B9B39C}';
  LXu_IMAGEPROCESSING              = '{1a89cc09-5326-44d6-9605-3b66bf9c03f5}';
  LXu_IMAGEPROCESSINGLISTENER      = '{4a4ca8b2-df07-4156-b1c3-a5fc63318ea8}';
  LXu_IMAGEPROCESSINGREAD          = '{154307c9-5fa3-4749-8853-088e2cc1f5ed}';
  LXu_IMAGEPROCESSINGSERVICE       = '{2f403a5c-a6aa-4d5a-88f6-a2dff23da523}';

type
  PLXtBuffer = ^Buffer   ;
  Buffer     = record end;

  PTileTree  = Pointer   ;

  ILxRenderService = interface
  [LXu_RENDERSERVICE]
    function ScriptQuery
             (  out VObj                                      ) : LxResult;

    function JobSetCurrent
             (      Job             : IUnknown                ) : LxResult;

    function JobCurrent
             (  out VObj                                      ) : LxResult;

    function JobStart                                           : LxResult;

    function JobAbort                                           : LxResult;

    function JobStatus                                          : LxResult;

    function JobStats                                           : IUnknown;

    function JobIsSlave                                         : Integer ;

    function JobCleanup
             (      ClearJob        : Integer                 ) : LxResult;

    function JobRenderOutputCount
             (      Count           : PInteger                ) : LxResult;

    function JobRenderOutputName
             (      Index           : Integer                 ;
              const Name            : PChar                   ) : LxResult;

    function JobRenderOutputType
             (      Index           : Integer                 ;
                    &Type           : PInteger                ) : LxResult;

    function UpdateProgressImage                                : LxResult;

    function RefreshProgressImageMetrics                        : LxResult;

    function FrameStore
             (      FrameBuffer     : IUnknown                ;
                    WritePixels     : Integer                 ) : LxResult;

    function FrameRecall
             (      SlotIndex       ,
                    PassIndex       : Integer                 ;
                    Monitor         : IUnknown                ;
                out VObj                                      ) : LxResult;

    function FrameTestRecall
             (      SlotIndex,
                    PassIndex       : Integer                 ) : LxResult;

    function FrameRenderPassCount
             (      SlotIndex       : Integer                 ;
                    NumPasses       : PInteger                ) : LxResult;

    function FrameRenderPassInfo
             (      SlotIndex,
                    PassIndex       : Integer                 ;
                    Name            : PChar                   ;
                    Width           : PUInt32                 ;
                    Height          : PUInt32                 ;
                    OutputCount     : PUInt32                 ;
                    IsStereo        : PInteger                ;
                    EyeDisplay      : PLXtStereoEye           ;
                    StereoComposite : PLXtStereoComposite     ) : LxResult;

    function FrameRenderPassOutputInfo
             (      SlotIndex       ,
                    PassIndex       : Integer                 ;
                    RenderPassName  : PChar                   ;
                    Width           ,
                    Height          : PUInt32                 ;
                    Outputs         : PRenderOutputProcessList) : LxResult;

    function FrameSaveImage
             (      Framebuffer     : IUnknown                ;
                    BufferIndex     : Integer                 ;
              const Filename        : PChar                   ;
              const Format          : PChar                   ;
                    Message         ,
                    Monitor         : IUnknown                ) : LxResult;

    function FrameSaveLayered
             (      Framebuffer     : IUnknown                ;
              const Filename        : PChar                   ;
              const Format          : PChar                   ;
                    Message         : IUnknown                ;
                    Monitor         : IUnknown                ) : LxResult;

    function FrameSavePassLayered
             (      Framebuffer     : IUnknown                ;
              const Filename        : PChar                   ;
              const Format          : PChar                   ;
                    Message         ,
                    Monitor         : IUnknown                ) : LxResult;

    function FrameSavePassesAsImages
             (      SlotIndex       : Integer                 ;
              const Filename        : PChar                   ;
              const Format          : PChar                   ;
                    Message         ,
                    Monitor         : IUnknown                ) : LxResult;

    function FrameSavePassesAsLayeredImages
             (      SlotIndex       : Integer                 ;
              const Filename        : PChar                   ;
              const Format          : PChar                   ;
                    Message         ,
                    Monitor         : IUnknown                ) : LxResult;

    function FrameStoreStats
             (      SlotIndex       : Integer                 ;
                    Stats           : IUnknown                ) : LxResult;

    function FrameRecallStats
             (      SlotIndex       : Integer                 ;
                out VObj                                      ) : LxResult;

    function FrameStoreThumbnail
             (      SlotIndex       : Integer                 ;
                    Image           : IUnknown                ) : LxResult;

    function FrameRecallThumbnail
             (      SlotIndex       : Integer                 ;
                out VObj                                      ) : LxResult;

    function FrameDelete
             (      SlotIndex       : Integer                 ) : LxResult;
  end;

  ILxRenderJob = interface
  [LXu_RENDERJOB]
    function RenderItem
             (  out VObj                         ) : LxResult;

    function ActionName
             (const Action             : PChar   ) : LxResult;

    function GroupName
             (const Group              : PChar   ) : LxResult;

    function RenderAs
             (      Mode               : PInteger) : LxResult;

    function RenderAtTime
             (      Time               : PDouble ) : LxResult;

    function RenderTurntableNumFrames
             (      NumFrames          : PInteger) : LxResult;

    function RenderTurntableFPS
             (      FPS                : PInteger) : LxResult;

    function RenderBakeVMap
             (const VMap               : PChar   ) : LxResult;

    function RenderBakeLookDistance
             (      Distance           : PDouble ) : LxResult;

    function RenderBakeItem
             (      Include            : PInteger;
                    Item               : PPointer) : LxResult;

    function RenderBakeEffect
             (const Effect             : PChar   ) : LxResult;

    function RenderBakeImage
             (  out VObj                         ) : LxResult;

    function TestItem
             (      Item               ,
                    Eval               : IUnknown) : LxResult;

    function FrameBufferSlot
             (      Index              : PInteger) : LxResult;

    function FrameBufferRegionBackgroundSlot
             (      SlotIndex          ,
                    PassIndex          : PInteger) : LxResult;

    function OutputFormat
             (const Format             : PChar   ) : LxResult;

    function OutputFilename
             (const Filename           : PChar   ) : LxResult;

    function Options
             (      Options            : PInteger) : LxResult;

    function ProgressAborted                       : LxResult;

    function ProgressBegin
             (      RenderStats        : IUnknown) : LxResult;

    function ProgressEnd
             (      FinalFrameBuffer   ,
                    FinalStats         : IUnknown) : LxResult;

    function ProgressPercentDone
             (      ProgressScene      ,
                    ProgressFrame      ,
                    ProgressRenderPass : Double  ) : LxResult;

    function ProgressImageMetrics
             (      ResX               ,
                    ResH               : Integer ;
                    W                  ,
                    H                  : PInteger;
                    Zoom               : PDouble ;
                    PanX                         ,
                    PanY               : PInteger;
                    Output             : PInteger) : LxResult;

    function ProgressFrameBegin
             (      Frame              ,
                    W                  ,
                    H                  : Integer ) : LxResult;

    function ProgressFrameEnd
             (      Frame              : Integer ;
                    Stats              : IUnknown) : LxResult;

    function ProgressRenderPassBegin
             (      FrameIndex         ,
                    RenderPassIndex    : Integer ;
              const RenderPassName     : PChar   ;
                    Eye                : Integer ) : LxResult;

    function ProgressRenderPassEnd
             (      Frame              ,
                    RenderPassIndex    : Integer ;
              const RenderPassName     : PChar   ;
                    Eye                : Integer ;
                    FrameBuffer        : IUnknown;
                    Stats              : IUnknown) : LxResult;

    function ProgressFramePassBegin
             (      Frame              ,
                    RenderPass         ,
                    Eye                ,
                    Pass               : Integer ) : LxResult;

    function ProgressFramePassEnd
             (      Frame              ,
                    RenderPass         ,
                    Eye                ,
                    Pass               : Integer ) : LxResult;

    function ProgressBucketBegin
             (      Row                ,
                    Col                : Integer ) : LxResult;

    function ProgressBucketEnd
             (      Row                ,
                    Col                : Integer ;
                    Code               : LxResult) : LxResult;

    function ProgressString
             (const InfoString         ,
                    UserString         : PChar   ) : LxResult;

    function ProgressImage
             (      Img                : IUnknown) : LxResult;

    function ProgressImageUpdated                  : LxResult;

    function ProgressTickle                        : LxResult;
  end;

  ILxRenderStats = interface
  [LXu_RENDERSTATS]
    function NumFrames    (    Count      : PInteger) : LxResult;
    function NumPasses    (    FrameIndex : Integer ;
                               Count      : PInteger) : LxResult;
    function GetPassStats (    FrameIndex ,
                               PassIndex  : Integer ;
                           out VObj                 ) : LxResult;
    function GetFrameStats(    FrameIndex : Integer ;
                           out VObj                 ) : LxResult;
    function GetSceneStats(out VObj                 ) : LxResult;
  end;

  ILxBuffer = interface
  [LXu_BUFFER]
    procedure SetFlags
              (      Flags              : Integer      ) ;

    function  Flags                                      : Integer      ;

    function  DataType                                   : Integer      ;

    function  VectorType                                 : ILxVectorType;

    procedure SetSize
              (      Width, Height      ,
                     WriteBucketsToDisk ,
                     IsStereo           : Integer      ) ;

    procedure GetSize
              (      Width, Height      : PInteger     ) ;

    function  SetEyeSide
              (      EyeSide            : Integer      ) : LxResult     ;

    procedure Clear
              (      X, Y               : Integer      ) ;

    function  Convert
              (      GV                 : PLXtGenVector;
                     X, Y               : Integer      ;
                     Blend              : Single       ) : LxResult     ;

    function  Pixel
              (      X, Y               : Integer      ) : Pointer      ;

    function  Line
              (      Y                  : Integer      ) : Pointer      ;

    function  Name
              (      Name               : PPChar       ) : LxResult     ;

    function  SetUserName
              (const Name_              : PChar        ) : LxResult     ;

    function  UserName
              (      Name_              : PPChar       ) : LxResult     ;

    function  CreateImageTileTree                        : LxResult     ;

    function  DestroyImageTileTree                       : LxResult     ;

    function  GetImageTileTree                           : PTileTree    ;

    function  GetImageTileTreeSize                       : SizeUInt     ;

    function  ResetImageTileTree                         : LxResult     ;

    function  IncrementTileTreeSize                      : LxResult     ;

    function  DecrementTileTreeSize                      : LxResult     ;
  end;

  ILxFrameBuffer  = interface
  [LXu_FRAMEBUFFER]
    function  Allocate
              (const Name               : PChar              ;
                     Item               : IUnknown           ;
               const Identity           : PChar              ;
               const UserName           : PChar              ;
                     IsFactoryName      : Integer            ;
                     WriteBucketsToDisk : Integer            ) : ILxBuffer;

    function  IsStereo
              (      IsStereo           : PInteger           ) : LxResult ;

    function  GetStereoEyeDisplay
              (      EyeDisplay         : PLXtStereoEye      ) : LxResult ;

    function  SetStereoEyeDisplay
              (      EyeDisplay         : LXtStereoEye       ) : LxResult ;

    function  GetStereoComposite
              (      Composite          : PLXtStereoComposite) : LxResult ;

    function  SetStereoComposite
              (      Composite          : LXtStereoComposite ) : LxResult ;

    function  SetEyeSide
              (      EyeSide            : Integer            ) : LxResult ;

    function  GetLineBuffer
              (      Buf                : PPSingle           ) : LxResult ;

    function  CreateFrameBufferTargetImage
              (      &Type              : LXtPixelFormat     ;
                     W, H               : Integer            ;
                 out VObj                                    ) : LxResult ;

    function  GetRenderPassName
              (      Name               : PChar              ) : LxResult ;

    function  SetRenderPassName
              (const Name               : PChar              ) : LxResult ;

    function  BucketsOnDisk
              (      Index              : Integer            ) : UInt32   ;

    function  Lookup
              (const Name               : PChar                           ;
                     Item               : IUnknown           ) : ILxBuffer;

    function  LookupByIdentity
              (const Identity           : PChar )              : ILxBuffer;

    function  Count                                            : UInt32   ;

    function  ByIndex
              (      Index              : Integer            ) : ILxBuffer;

    function  Alpha
              (      Index              : Integer            ) : ILxBuffer;

    function  AlphaIndex
              (      Index              : Integer            ) : Integer  ;

    function  Size
              (      Index              : Integer            ;
                     Width, Height      : PInteger           ) : LxResult ;

    function  AreaProcessingActive
              (      BufferIndex        : Integer            ;
                     Active             : PInteger           ) : LxResult ;

    function  GetSaveProcessed
              (      BufferIndex        : Integer            ) : Integer  ;

    function  SetSaveProcessed
              (      BufferIndex        ,
                     Enabled            : Integer            ) : LxResult ;

    function  GetBloomEnabled
              (      BufferIndex        : Integer            ) : Integer  ;

    function  SetBloomEnabled
              (      BufferIndex        ,
                     Enabled            : Integer            ) : LxResult ;

    function  GetBloomThreshold
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetBloomThreshold
              (      BufferIndex        : Integer            ;
                     Threshold          : Double             ) : LxResult ;

    function  GetBloomRadius
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetBloomRadius
              (      BufferIndex        : Integer            ;
                     Radius             : Double             ) : LxResult ;

    function  GetLevelOffset
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetLevelOffset
              (      BufferIndex        : Integer            ;
                     Offset             : Double             ) : LxResult ;

    function  GetRedLevelOffset
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetRedLevelOffset
              (      BufferIndex        : Integer            ;
                     Offset             : Double             ) : LxResult ;

    function  GetGreenLevelOffset
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetGreenLevelOffset
              (      BufferIndex        : Integer            ;
                     Offset             : Double             ) : LxResult ;

    function  GetBlueLevelOffset
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetBlueLevelOffset
              (      BufferIndex        : Integer            ;
                     Offset             : Double             ) : LxResult ;

    function  GetInputBlackLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetInputBlackLevel
              (      BufferIndex        : Integer            ;
                     BlackLevel         : Double             ) : LxResult ;

    function  GetInputGrayLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  GetInvInputGrayLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetInputGrayLevel
              (      BufferIndex        : Integer            ;
                     Gamma              : Double             ) : LxResult ;

    function  GetInputWhiteLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetInputWhiteLevel
              (      BufferIndex        : Integer            ;
                     WhiteLevel         : Double             ) : LxResult ;

    function  GetInputMinRedLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetInputMinRedLevel
              (      BufferIndex        : Integer            ;
                     Level              : Double             ) : LxResult ;

    function  GetInputRedGrayLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  GetInvInputRedGrayLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetInputRedGrayLevel
              (      BufferIndex        : Integer            ;
                     Gamma              : Double             ) : LxResult ;

    function  GetInputMaxRedLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetInputMaxRedLevel
              (      BufferIndex        : Integer            ;
                     Level              : Double             ) : LxResult ;

    function  GetInputMinGreenLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetInputMinGreenLevel
              (      BufferIndex        : Integer            ;
                     Level              : Double             ) : LxResult ;

    function  GetInputGreenGrayLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  GetInvInputGreenGrayLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetInputGreenGrayLevel
              (      BufferIndex        : Integer            ;
                     Gamma              : Double             ) : LxResult ;

    function  GetInputMaxGreenLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetInputMaxGreenLevel
              (      BufferIndex        : Integer            ;
                     Level              : Double             ) : LxResult ;

    function  GetInputMinBlueLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetInputMinBlueLevel
              (      BufferIndex        : Integer            ;
                     Level              : Double             ) : LxResult ;

    function  GetInputBlueGrayLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  GetInvInputBlueGrayLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetInputBlueGrayLevel
              (      BufferIndex        : Integer            ;
                     Gamma              : Double             ) : LxResult ;

    function  GetInputMaxBlueLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetInputMaxBlueLevel
              (      BufferIndex        : Integer            ;
                     Level              : Double             ) : LxResult ;

    function  GetToneMapping
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetToneMapping
              (      BufferIndex        : Integer            ;
                     ToneMapping        : Double             ) : LxResult ;

    function  GetHueOffset
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetHueOffset
              (      BufferIndex        : Integer            ;
                     HueOffset          : Double             ) : LxResult ;

    function  GetSaturation
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetSaturation
              (      BufferIndex        : Integer            ;
                     Saturation         : Double             ) : LxResult ;

    function  GetColorization
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetColorization
              (      BufferIndex        : Integer            ;
                     Colorization       : Double             ) : LxResult ;

    procedure GetTargetColor
              (      BufferIndex        : Integer            ;
                     Color              : PDouble            ) ;

    function  SetTargetColor
              (      BufferIndex        : Integer            ;
               const Color              : PDouble            ) : LxResult ;

    function  GetOutputBlackLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetOutputBlackLevel
              (      BufferIndex        : Integer            ;
                     BlackLevel         : Double             ) : LxResult ;

    function  GetOutputWhiteLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetOutputWhiteLevel
              (      BufferIndex        : Integer            ;
                     WhiteLevel         : Double             ) : LxResult ;

    function  GetOutputMinRedLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetOutputMinRedLevel
              (      BufferIndex        : Integer            ;
                     BlackLevel         : Double             ) : LxResult ;

    function  GetOutputMaxRedLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetOutputMaxRedLevel
              (      BufferIndex        : Integer            ;
                     WhiteLevel         : Double             ) : LxResult ;

    function  GetOutputMinGreenLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetOutputMinGreenLevel
              (      BufferIndex        : Integer            ;
                     BlackLevel         : Double             ) : LxResult ;

    function  GetOutputMaxGreenLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetOutputMaxGreenLevel
              (      BufferIndex        : Integer            ;
                     WhiteLevel         : Double             ) : LxResult ;

    function  GetOutputMinBlueLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetOutputMinBlueLevel
              (      BufferIndex        : Integer            ;
                     BlackLevel         : Double             ) : LxResult ;

    function  GetOutputMaxBlueLevel
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetOutputMaxBlueLevel
              (      BufferIndex        : Integer            ;
                     WhiteLevel         : Double             ) : LxResult ;

    function  GetOutputGamma
              (      BufferIndex        : Integer            ) : Double   ;

    function  GetOutputInvGamma
              (      BufferIndex        : Integer            ) : Double   ;

    function  SetOutputGamma
              (      BufferIndex        : Integer            ;
                     Gamma              : Double             ) : LxResult ;

    function  AddAttribute
              (const Name               : PChar              ;
               const &Type              : PChar              ;
                     Index              : PUInt32            ) : LxResult ;
  end;

  ILxImageProcessing  = interface
  [LXu_IMAGEPROCESSING]
    function GetAsReadOnly
             (  out VObj                                           ) : LxResult;

    function SetIdentifier
             (const &String          : PChar                       ) : LxResult;

    function GetIdentifier
             (const &String          : PChar                       ) : LxResult;

    function Reset                                                   : LxResult;

    function CopyToRenderProcess
             (      ROP              : PRenderOutputProcess        ) : LxResult;

    function CopyFromRenderProcess
             (const ROP              : PRenderOutputProcess        ) : LxResult;

    function CopySettingsFromFrameBuffer
             (      FrameBuffer      : IUnknown                    ;
                    BufferIndex      : Integer                     ) : LxResult;

    function CopySettingsToFrameBuffer
             (      FrameBuffer      : IUnknown                    ;
                    BufferIndex      : Integer                     ) : LxResult;

    function ApplyToImageFromFrameBuffer
             (      FrameBuffer      : IUnknown                    ;
                    BufferIndex      : Integer                     ;
                    Image            : IUnknown                    ;
                    XOffset          ,
                    YOffset          ,
                    Zoom             : Single                      ) : LxResult;

    function ApplyToImageFromFrameBufferOverride
             (      FrameBuffer      : IUnknown                    ;
                    BufferIndex      : Integer                     ;
                    Image            : IUnknown                    ;
                    XOffset          ,
                    YOffset          ,
                    Zoom             : Single                      ;
                    OpOverride       : LXtImageProcessingOperators ) : LxResult;

    function ApplyToFrameBuffer
             (      FrameBuffer      : IUnknown                    ;
                    BufferIndex      : Integer                     ) : LxResult;

    function ApplyToFrameBufferOverride
             (      FrameBuffer      : IUnknown                    ;
                    BufferIndex      : Integer                     ;
                    OpOverride       : LXtImageProcessingOperators ) : LxResult;

    function ApplyToImage
             (      SrcImage         ,
                    DstImage         : IUnknown                    ) : LxResult;

    function ApplyToImageOverride
             (      SrcImage         ,
                    DstImage         : IUnknown                    ;
                    OpOverride       : LXtImageProcessingOperators ) : LxResult;

    function GetImageProcessingOperators
             (      Ops              : PLXtImageProcessingOperators) : LxResult;

    function SetImageProcessingOperators
             (      Ops              : LXtImageProcessingOperators ) : LxResult;

    function AreaProcessingActive
             (      Active           : PInteger                    ) : LxResult;

    function GetSourceImageGamma
             (      Gamma            : PDouble                     ) : LxResult;

    function SetSourceImageGamma
             (      Gamma            : Double                      ) : LxResult;

    function GetSourceImageIsStereoSideBySide
             (      IsStereo         : PInteger                    ) : LxResult;

    function SetSourceImageIsStereoSideBySide
             (      IsStereo         : Integer                     ) : LxResult;

    function GetSaveProcessed
             (      Enabled          : PInteger                    ) : LxResult;

    function SetSaveProcessed
             (      Enabled          : Integer                     ) : LxResult;

    function GetStereoEye
             (      Eye              : PLXtStereoEye               ) : LxResult;

    function SetStereoEye
             (      Eye              : LXtStereoEye                ) : LxResult;

    function GetStereoComposite
             (      Mode             : PLXtStereoComposite         ) : LxResult;

    function SetStereoComposite
             (      Mode             : LXtStereoComposite          ) : LxResult;

    function GetBloomEnabled
             (      Enabled          : PInteger                    ) : LxResult;

    function SetBloomEnabled
             (      Enabled          : Integer                     ) : LxResult;

    function GetBloomThreshold
             (      Threshold        : PDouble                     ) : LxResult;

    function SetBloomThreshold
             (      Threshold        : Double                      ) : LxResult;

    function GetBloomRadius
             (      Radius           : PDouble                     ) : LxResult;

    function SetBloomRadius
             (      Radius           : Double                      ) : LxResult;

    function GetLevelOffset
             (      Offset           : PDouble                     ) : LxResult;

    function SetLevelOffset
             (      Offset           : Double                      ) : LxResult;

    function GetRedLevelOffset
             (      Offset           : PDouble                     ) : LxResult;

    function SetRedLevelOffset
             (      Offset           : Double                      ) : LxResult;

    function GetGreenLevelOffset
             (      Offset           : PDouble                     ) : LxResult;

    function SetGreenLevelOffset
             (      Offset           : Double                      ) : LxResult;

    function GetBlueLevelOffset
             (      Offset           : PDouble                     ) : LxResult;

    function SetBlueLevelOffset
             (      Offset           : Double                      ) : LxResult;

    function GetInputBlackLevel
             (      InputBlackLevel  : PDouble                     ) : LxResult;

    function SetInputBlackLevel
             (      BlackLevel       : Double                      ) : LxResult;

    function GetInputGrayLevel
             (      Gamma            : PDouble                     ) : LxResult;

    function GetInvInputGrayLevel
             (      InvGamma         : PDouble                     ) : LxResult;

    function SetInputGrayLevel
             (      Gamma            : Double                      ) : LxResult;

    function GetInputWhiteLevel
             (      InputWhiteLevel  : PDouble                     ) : LxResult;

    function SetInputWhiteLevel
             (      WhiteLevel       : Double                      ) : LxResult;

    function GetInputMinRedLevel
             (      InputLevel       : PDouble                     ) : LxResult;

    function SetInputMinRedLevel
             (      Level            : Double                      ) : LxResult;

    function GetInputRedGrayLevel
             (      Gamma            : PDouble                     ) : LxResult;

    function GetInvInputRedGrayLevel
             (      InvGamma         : PDouble                     ) : LxResult;

    function SetInputRedGrayLevel
             (      Gamma            : Double                      ) : LxResult;

    function GetInputMaxRedLevel
             (      InputLevel       : PDouble                     ) : LxResult;

    function SetInputMaxRedLevel
             (      Level            : Double                      ) : LxResult;

    function GetInputMinGreenLevel
             (      InputLevel       : PDouble                     ) : LxResult;

    function SetInputMinGreenLevel
             (      Level            : Double                      ) : LxResult;

    function GetInputGreenGrayLevel
             (      Gamma            : PDouble                     ) : LxResult;

    function GetInvInputGreenGrayLevel
             (      InvGamma         : PDouble                     ) : LxResult;

    function SetInputGreenGrayLevel
             (      Gamma            : Double                      ) : LxResult;

    function GetInputMaxGreenLevel
             (      InputLevel       : PDouble                     ) : LxResult;

    function SetInputMaxGreenLevel
             (      Level            : Double                      ) : LxResult;

    function GetInputMinBlueLevel
             (      InputLevel       : PDouble                     ) : LxResult;

    function SetInputMinBlueLevel
             (      Level            : Double                      ) : LxResult;

    function GetInputBlueGrayLevel
             (      Gamma            : PDouble                     ) : LxResult;

    function GetInvInputBlueGrayLevel
             (      InvGamma         : PDouble                     ) : LxResult;

    function SetInputBlueGrayLevel
             (      Gamma            : Double                      ) : LxResult;

    function GetInputMaxBlueLevel
             (      InputLevel       : PDouble                     ) : LxResult;

    function SetInputMaxBlueLevel
             (      Level            : Double                      ) : LxResult;

    function GetToneMapping
             (      ToneMapping      : PDouble                     ) : LxResult;

    function SetToneMapping
             (      ToneMapping      : Double                      ) : LxResult;

    function GetHueOffset
             (      HueOffset        : PDouble                     ) : LxResult;

    function SetHueOffset
             (      HueOffset        : Double                      ) : LxResult;

    function GetSaturation
             (      Saturation       : PDouble                     ) : LxResult;

    function SetSaturation
             (      Saturation       : Double                      ) : LxResult;

    function GetColorization
             (      Colorization     : PDouble                     ) : LxResult;

    function SetColorization
             (      Colorization     : Double                      ) : LxResult;

    function GetTargetColor
             (      Color            : PDouble                     ) : LxResult;

    function SetTargetColor
             (const Color            : PDouble                     ) : LxResult;

    function GetOutputBlackLevel
             (      OutputBlackLevel : PDouble                     ) : LxResult;

    function SetOutputBlackLevel
             (      BlackLevel       : Double                      ) : LxResult;

    function GetOutputWhiteLevel
             (      OutputWhiteLevel : PDouble                     ) : LxResult;

    function SetOutputWhiteLevel
             (      WhiteLevel       : Double                      ) : LxResult;

    function GetOutputMinRedLevel
             (      OutputLevel      : PDouble                     ) : LxResult;

    function SetOutputMinRedLevel
             (      OutputLevel      : Double                      ) : LxResult;

    function GetOutputMaxRedLevel
             (      OutputLevel      : PDouble                     ) : LxResult;

    function SetOutputMaxRedLevel
             (      OutputLevel      : Double                      ) : LxResult;

    function GetOutputMinGreenLevel
             (      OutputLevel      : PDouble                     ) : LxResult;

    function SetOutputMinGreenLevel
             (      OutputLevel      : Double                      ) : LxResult;

    function GetOutputMaxGreenLevel
             (      OutputLevel      : PDouble                     ) : LxResult;

    function SetOutputMaxGreenLevel
             (      OutputLevel      : Double                      ) : LxResult;

    function GetOutputMinBlueLevel
             (      OutputLevel      : PDouble                     ) : LxResult;

    function SetOutputMinBlueLevel
             (      OutputLevel      : Double                      ) : LxResult;

    function GetOutputMaxBlueLevel
             (      OutputLevel      : PDouble                     ) : LxResult;

    function SetOutputMaxBlueLevel
             (      OutputLevel      : Double                      ) : LxResult;

    function GetOutputGamma
             (      OutputGamma      : PDouble                     ) : LxResult;

    function GetOutputInvGamma
             (      OutputInvGamma   : PDouble                     ) : LxResult;

    function SetOutputGamma
             (      Gamma            : Double                      ) : LxResult;
  end;

  ILxImageProcessingListener = interface
  [LXu_IMAGEPROCESSINGLISTENER]
    function Changed(const Identifier : PChar  ;
                           EventCode  : Integer) : LxResult;
    function Reset  (const Identifier : PChar  ) : LxResult;
  end;

  ILxImageProcessingRead = interface
  [LXu_IMAGEPROCESSINGREAD]
    function GetIdentifier
             (const &String        : PChar                       ) : LxResult;

    function CopyToRenderProcess
             (      ROP            : PRenderOutputProcess        ) : LxResult;

    function CopySettingsToFrameBuffer
             (      FrameBuffer    : IUnknown                    ;
                    BufferIndex    : Integer                     ) : LxResult;

    function ApplyToImageFromFrameBuffer
             (      FrameBuffer    : IUnknown                    ;
                    BufferIndex    : Integer                     ;
                    Image          : IUnknown                    ;
                    XOffset        ,
                    YOffset        ,
                    Zoom           : Single                      ) : LxResult;

    function ApplyToImageFromFrameBufferOverride
             (      FrameBuffer    : IUnknown                    ;
                    BufferIndex    : Integer                     ;
                    Image          : IUnknown                    ;
                    XOffset        ,
                    YOffset        ,
                    Zoom           : Single                      ;
                    OpOverride     : LXtImageProcessingOperators ) : LxResult;

    function ApplyToFrameBuffer
             (      FrameBuffer    : IUnknown                    ;
                    BufferIndex    : Integer                     ) : LxResult;

    function ApplyToFrameBufferOverride
             (      FrameBuffer    : IUnknown                    ;
                    BufferIndex    : Integer                     ;
                    OpOverride     : LXtImageProcessingOperators ) : LxResult;

    function ApplyToImage
             (      SrcImage       ,
                    DstImage       : IUnknown                    ) : LxResult;

    function ApplyToImageOverride
             (      SrcImage       ,
                    DstImage       : IUnknown                    ;
                    OpOverride     : LXtImageProcessingOperators ) : LxResult;

    function GetImageProcessingOperators
             (      Ops            : PLXtImageProcessingOperators) : LxResult;

    function AreaProcessingActive
             (      Active         : PInteger                    ) : LxResult;

    function GetSourceImageGamma
             (      Gamma          : PDouble                     ) : LxResult;

    function GetSourceImageIsStereoSideBySide
             (      IsStereo       : PInteger                    ) : LxResult;

    function GetSaveProcessed
             (      Enabled        : PInteger                    ) : LxResult;

    function GetStereoEye
             (      Eye            : PInteger                    ) : LxResult;

    function GetStereoComposite
             (      Mode           : PInteger                    ) : LxResult;

    function GetBloomEnabled
             (      Enabled        : PInteger                    ) : LxResult;

    function GetBloomThreshold
             (      Threshold      : PDouble                     ) : LxResult;

    function GetBloomRadius
             (      Radius         : PDouble                     ) : LxResult;

    function GetLevelOffset
             (      Offset         : PDouble                     ) : LxResult;

    function GetRedLevelOffset
             (      Offset         : PDouble                     ) : LxResult;

    function GetGreenLevelOffset
             (      Offset         : PDouble                     ) : LxResult;

    function GetBlueLevelOffset
             (      Offset         : PDouble                     ) : LxResult;

    function GetInputBlackLevel
             (      InputLevel     : PDouble                     ) : LxResult;

    function GetInputGrayLevel
             (      Gamma          : PDouble                     ) : LxResult;

    function GetInvInputGrayLevel
             (      InvGamma       : PDouble                     ) : LxResult;

    function GetInputWhiteLevel
             (      InputLevel     : PDouble                     ) : LxResult;

    function GetInputMinRedLevel
             (      InputLevel     : PDouble                     ) : LxResult;

    function GetInputRedGrayLevel
             (      Gamma          : PDouble                     ) : LxResult;

    function GetInvInputRedGrayLevel
             (      InvGamma       : PDouble                     ) : LxResult;

    function GetInputMaxRedLevel
             (      InputLevel     : PDouble                     ) : LxResult;

    function GetInputMinGreenLevel
             (      InputLevel     : PDouble                     ) : LxResult;

    function GetInputGreenGrayLevel
             (      Gamma          : PDouble                     ) : LxResult;

    function GetInvInputGreenGrayLevel
             (      InvGamma       : PDouble                     ) : LxResult;

    function GetInputMaxGreenLevel
             (      InputLevel     : PDouble                     ) : LxResult;

    function GetInputMinBlueLevel
             (      InputLevel     : PDouble                     ) : LxResult;

    function GetInputBlueGrayLevel
             (      Gamma          : PDouble                     ) : LxResult;

    function GetInvInputBlueGrayLevel
             (      InvGamma       : PDouble                     ) : LxResult;

    function GetInputMaxBlueLevel
             (      InputLevel     : PDouble                     ) : LxResult;

    function GetToneMapping
             (      ToneMapping    : PDouble                     ) : LxResult;

    function GetHueOffset
             (      HueOffset      : PDouble                     ) : LxResult;

    function GetSaturation
             (      Saturation     : PDouble                     ) : LxResult;

    function GetColorization
             (      Colorization   : PDouble                     ) : LxResult;

    function GetTargetColor
             (      Color          : PDouble                     ) : LxResult;

    function GetOutputBlackLevel
             (      OutputLevel    : PDouble                     ) : LxResult;

    function GetOutputWhiteLevel
             (      OutputLevel    : PDouble                     ) : LxResult;

    function GetOutputMinRedLevel
             (      OutputLevel    : PDouble                     ) : LxResult;

    function GetOutputMaxRedLevel
             (      OutputLevel    : PDouble                     ) : LxResult;

    function GetOutputMinGreenLevel
             (      OutputLevel    : PDouble                     ) : LxResult;

    function GetOutputMaxGreenLevel
             (      OutputLevel    : PDouble                     ) : LxResult;

    function GetOutputMinBlueLevel
             (      OutputLevel    : PDouble                     ) : LxResult;

    function GetOutputMaxBlueLevel
             (      OutputLevel    : PDouble                     ) : LxResult;

    function GetOutputGamma
             (      OutputGamma    : PDouble                     ) : LxResult;

    function GetOutputInvGamma
             (      OutputInvGamma : PDouble                     ) : LxResult;
  end;

  ILxImageProcessingService = interface
  [LXu_IMAGEPROCESSINGSERVICE]
    function ScriptQuery(out VObj) : LxResult;
    function Create     (out VObj) : LxResult;
  end;

function LXe_RENDER_IDLE              : LxResult;
function LXe_RENDER_RENDERING         : LxResult;
function LXe_RENDER_USE_OUTPUT_ITEMS  : LxResult;
function LXe_RENDER_WITHOUT_SAVING    : LxResult;

function LXe_RENDER_NO_JOB            : LxResult;
function LXe_RENDER_IN_PROGRESS       : LxResult;
function LXe_RENDER_NOT_RENDERING     : LxResult;

function LXe_RENDER_ABORTING          : LxResult;

function LXe_RENDER_NO_PROGRESS_IMAGE : LxResult;

implementation

function LXe_RENDER_IDLE              : LxResult; inline;
begin
  Result := LXxGOODCODE(LXeSYS_RENDER, 1);
end;
function LXe_RENDER_RENDERING         : LxResult; inline;
begin
  Result := LXxGOODCODE(LXeSYS_RENDER, 2);
end;
function LXe_RENDER_USE_OUTPUT_ITEMS  : LxResult; inline;
begin
  Result := LXxGOODCODE(LXeSYS_RENDER, 3);
end;
function LXe_RENDER_WITHOUT_SAVING    : LxResult; inline;
begin
  Result := LXxGOODCODE(LXeSYS_RENDER, 4);
end;
function LXe_RENDER_NO_JOB            : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_RENDER, 1);
end;
function LXe_RENDER_IN_PROGRESS       : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_RENDER, 2);
end;
function LXe_RENDER_NOT_RENDERING     : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_RENDER, 3);
end;
function LXe_RENDER_ABORTING          : LxResult; inline;
begin
  Result := LXe_ABORT;
end;
function LXe_RENDER_NO_PROGRESS_IMAGE : LxResult; inline;
begin
  Result := LXxGOODCODE(LXeSYS_RENDER, 5);
end;

end.

